import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { ECategory } from "../../../../Message/Public/ECategory";
import { ObjectPool } from "../../../../com/gengine/utils/pools/ObjectPool";
import { WuXingGradeEquipItem } from "./WuXingGradeEquipItem";
import { ItemData } from "../../resource/info/ItemData";
//class WuXingGradeEquipList
    
    export  class WuXingGradeEquipList /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._refreshTypes = [];
            this.initUI();
            return;
        }

        public get isShowLingZhu(): Boolean
        {
            return this._isShowLingZhu;
        }

        public set isShowLingZhu(arg1: Boolean)
        {
            this._isShowLingZhu = arg1;
            return;
        }

        /* internal  */onEquipPosFrameLoaded(): void
        {
            this._equipPosFrame = GlobalClass.getInstance("WXGradeFrame");
            this._equipPosBody.addChild(this._equipPosFrame);
            this.refreshEquip(this._equipList);
            return;
        }

        protected onWuXingBgLoadedHandler(): void
        {
            this._titleBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.wxEquipFont);
            return;
        }

        protected initUI(): void
        {
            this._titleBmp = new Object /* flash.display.Bitmap */();
            this._titleBmp.x = 10;
            this._titleBmp.y = -28;
            addChild(this._titleBmp);
            this._equipPosBody = new Object /* flash.display.Sprite */();
            this._equipPosBody.x = 0;
            this._equipPosBody.y = 0;
            this._equipPosBody.mouseChildren = false;
            this._equipPosBody.mouseEnabled = false;
            addChild(this._equipPosBody);
            this._listBody = new Object /* flash.display.Sprite */();
            addChild(this._listBody);
            LoaderHelp.addResCallBack("EquipPosFrame.swf", this.onEquipPosFrameLoaded);
            LoaderHelp.addResCallBack(ResFileConst.wuxing, this.onWuXingBgLoadedHandler);
            return;
        }

        protected refreshEquip(arg1: Array<any>): void
        {
            var loc1=0;
            var loc2=0;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            this.clearEquip();
            if (arg1 && this._equipPosFrame) 
            {
                loc1 = 0;
                loc2 = arg1.length;
                while (loc1 < loc2) 
                {
                    if ((loc4 = arg1[loc1]) && loc4.category == ECategory._ECategoryEquip) 
                    {
                        loc5 = this._equipPosFrame["EquipPos_" + loc4.type];
                        if (this._refreshTypes.indexOf(loc4.type) != -1) 
                        {
                            loc5 = this._equipPosFrame["EquipPos_" + loc4.type + "_1"];
                        }
                        this._refreshTypes.push(loc4.type);
                        if (loc5) 
                        {
                            (loc3 = ObjectPool.getObject(WuXingGradeEquipItem)).updateData(loc4, this.isShowLingZhu);
                            loc3.x = loc5.x;
                            loc3.y = loc5.y;
                            this._listBody.addChild(loc3);
                        }
                    }
                    ++loc1;
                }
            }
            return;
        }

        public updateData(arg1: Array<any>): void
        {
            this._equipList = arg1;
            this.refreshEquip(this._equipList);
            return;
        }

        protected clearEquip(): void
        {
            var loc1=null;
            this._refreshTypes.splice(0);
            while (this._listBody.numChildren > 0) 
            {
                loc1 = this._listBody.removeChildAt(0) as WuXingGradeEquipItem;
                loc1.dispose();
                ObjectPool.disposeObject(loc1, WuXingGradeEquipItem);
            }
            return;
        }

        public getListItemByItem(arg1: ItemData): WuXingGradeEquipItem
        {
            if (arg1) 
            {
                return this.getListItemByItemCode(arg1.uid);
            }
            return null;
        }

        public getListItemByItemCode(arg1: string): WuXingGradeEquipItem
        {
            var loc1=0;
            var loc3=null;
            var loc2=this._listBody.numChildren;
            while (loc1 < loc2) 
            {
                if ((loc3 = this._listBody.getChildAt(loc1) as WuXingGradeEquipItem).item && loc3.item.uid == arg1) 
                {
                    return loc3;
                }
                ++loc1;
            }
            return null;
        }

        public dispose(): void
        {
            return;
        }

        /* internal */ /* var */_titleBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_equipPosFrame: Object /* flash.display.MovieClip */;

        /* internal */ /* var */_equipPosBody: Object /* flash.display.Sprite */;

        /* internal */ /* var */_equipList: Array<any>;

        /* internal */ /* var */_listBody: Object /* flash.display.Sprite */;

        /* internal */ /* var */_isShowLingZhu: Boolean=true;

        /* internal */ /* var */_refreshTypes: Array<any>;
    }
